﻿Public Class ChildState

    Private _StateId As Integer
    Private _StateName As String

    Public Sub New()

    End Sub

    Public Sub New(ByVal iStateId As Integer, ByVal sStateName As String)
        StateId = iStateId
        StateName = sStateName
    End Sub

    Public Property StateId As Integer
        Get
            StateId = _StateId
        End Get
        Set(ByVal value As Integer)
            _StateId = value
        End Set
    End Property

    Public Property StateName As String
        Set(ByVal value As String)
            _StateName = value
        End Set
        Get
            StateName = _StateName
        End Get
    End Property

    Public Shared Function State(ByVal iState As Integer) As ChildState
        Dim oState As ChildState = Nothing
        For Each oState In StatesList()
            If oState.StateId = iState Then
                Return oState
            End If
        Next
        Return oState
    End Function

    Public Shared Function States() As DataTable
        Dim dt As New DataTable

        Dim ret As Integer = DatabaseLayer.DatabaseManager.StoredProc("uspGetChildStates", dt, User.CurrentUser.ID)

        Return dt
    End Function

    Public Shared Function StatesList() As List(Of ChildState)

        Dim dt As DataTable = States()
        Dim oStatesList As New List(Of ChildState)
        For Each dtrow As DataRow In dt.Rows
            Dim oState As New ChildState
            oState.StateId = dtrow("stateId")
            oState.StateName = dtrow("stateName")
            oStatesList.Add(oState)
        Next
        Return oStatesList

    End Function

End Class
